/* Sentinel - IRC Statistical and Operator Services
** struct.h - Structure definitions
**
** Copyright W. Campbell and others.  See README for more details
** Some code Copyright: Jonathan George, Kai Seidler, ircd-hybrid Team,
**                      IRCnet IRCD developers.
**
** $Id: struct.h 10 2010-02-02 01:12:49Z dubkat $
*/

#ifndef STRUCT_H
#define STRUCT_H

#include "stats.h"
#include "setup.h"

#ifdef HAVE_LIBCRYPTO
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/bio.h>
#include <openssl/rand.h>
#include <openssl/err.h>
#endif

#define PFLAG_VHOST	0x00000001

#define FLAG_NOTIFYEOB	0x00000001
#define FLAG_JUPE_PERSIST	0x00000002
#define FLAG_HTML	0x00000004
#define FLAG_DUMP	0x00000008
#define FLAG_HIDE	0x00000010
#define FLAG_FLOOD	0x00000020
#define FLAG_AONLYOPERS 0x00000040
#define FLAG_SILENT	0x00000080
#define FLAG_UNAUTHCHAT	0x00000100
#define FLAG_DCCOPERONLY	0x00000200
#define FLAG_PUBDELAYED	0x00000400
#define FLAG_MON_NG	0x00000800
#define FLAG_IGNORE_ILLEGAL_TLD	0x00001000
#define FLAG_SPYWALLOPS	0x00002000
#define FLAG_OPERSADMINONLY	0x00004000
#define FLAG_JUPE_ALLOPER      0x00008000
#define FLAG_TRACKFIZZER	0x00010000 
/* 0x00020000 and 0x00040000 */
#define FLAG_EOB	0x00080000

#define STFLAG_OPERONLY	0x00000001
#define STFLAG_SETOPER	0x00000004

#define UFLAG_FLOODSENT	0x00000001
#define UFLAG_ISOPER	0x00000002
#define UFLAG_ISAWAY	0x00000004
#define UFLAG_INVIS	0x00000008

#define MFLAG_ISON	0x00000001
#define MFLAG_DCC	0x00000002
#define MFLAG_DYING	0x00000004 
/* Oper flags */
#define MFLAG_ADMIN	0x00000010
#define MFLAG_STATS	0x00000020
#define MFLAG_SPLIT	0x00000040
#define MFLAG_JUPE	0x00000080
#define MFLAG_LIST	0x00000100
#define MFLAG_OP	0x00000200
#define MFLAG_TAKEOVER	0x00000400

#define SFLAG_HIDE	0x00000001

#define CMD_DEBUG       0x00000001
#define CMD_NOFORK      0x00000002

#define OPER_GLOBAL	0x00000002
#define OPER_ADMIN	0x00000004
#define OPER_MYOPER	0x00000008
#define OPER_SVSADMIN	0x00000010

/* For bnet... */
#define BG_SVSADMIN	0x00000002

#define SPF_ENABLE_TEXT	0x00000004
#define SPF_REPORT	0x00000008
#define SPF_EXPIRE	0x00000010
#define SPF_HIDE	0x00000020
#define SPF_REMIND	0x00000040
#define SPF_OPERONLY	0x00000080
#define SPF_TRACKONDISCONNECT	0x00000100

/* SplitServ has some options to define which functions are available to
** whom.  They are defined here.
*/

/* Default to OPEN */
#define SO_OPEN		0
#define SO_OPERONLY	1
#define SO_DISABLED	2

#define CONN_SERV	0x00000001
#define CONN_DCCOUT	0x00000002
#define CONN_DCCIN	0x00000004
#define CONN_DEAD	0x00000008
#define CONN_CONNECTING	0x00000010
#define CONN_NOECHO	0x00000020

/* To save some space, I will include the "usermodes" into the same flags
** variable
*/
#define CF_AUTH		0x80000000
#define CF_NOTICES	0x40000000
#define CF_JUPE		0x20000000
#define CF_OPER		0x10000000
#define CF_COMMANDS	0x08000000
#define CF_USER		0x04000000
#define CF_KILL		0x02000000
#define CF_MISC		0x01000000
#define CF_SERVICES	0x00800000
#define CF_TLD		0x00400000
#define CF_CHAT		0x00200000

/* And an aggregate for .flags all and .flags -all */
#define CF_ALL		(CF_AUTH|CF_NOTICES|CF_JUPE|CF_OPER|CF_COMMANDS|\
                 CF_USER|CF_KILL|CF_MISC|CF_SERVICES|CF_TLD|CF_CHAT)

/* Channel modes */
#define CMODE_BAN	0x00000000 /* IGNORE */
#define CMODE_INVITE	0x00000001
#define CMODE_KEY	0x00000002
#define CMODE_LIMIT	0x00000004
#define CMODE_MOD	0x00000008
#define CMODE_NOEXT	0x00000010
#define CMODE_OP	0x00000020 /* SPECIAL */
#define CMODE_PRIV	0x00000040 /* AKA PARA */
#define CMODE_SEC	0x00000080
#define CMODE_TOPIC	0x00000100
#define CMODE_VOICE	0x00000200 /* SPECIAL */
#define CMODE_EXEMPT	0x00000000 /* IGNORE */
#define CMODE_INVEX	0x00000000 /* IGNORE */
#define CMODE_HALFOP	0x00000400 /* SPECIAL */
/* 0x00000800 - 0x00001000 */
#define CMODE_OPERONLY	0x00002000
#define CMODE_REGISTERED	0x00004000
#define CMODE_REGONLY	0x00008000
#define CMODE_JUPED	0x00010000 /* Hybrid JUPE, not propogated normally */
#define CMODE_NOCOLOUR	0x00020000

struct netinfo
{
  long inb;
  long outb;
  int opers;
  int maxopers;
  long users;
  long maxusers;
  int servers;
  int maxservers;
  time_t t_maxopers;
  time_t t_maxusers;
  time_t t_maxservers;
  int away;
  int maxaway;
  time_t t_maxaway;
  long invis;
  int requests;
  long channels;
  long maxchannels;
  time_t t_maxchannels;
#ifdef DIE_ON_MASS_COLLIDE

  int collides;
#endif

  long connections;
}
netinfo;

struct memcounts
{
  int myuser;
  int connection;
  int hidden;
#ifdef JUPESERV

  int jupe;
  int jupevote;
#endif
#ifdef SPLITSERV

  int spserver;
#endif

  int stats;
  int tld;
  int native;
  int nativemem;
  int chanuser;
  int channel;
#ifdef TRACK_GECOS

  int gecos;
  int gecosmem;
#endif
#ifdef MONSERV

  int hashent;
  int ignoreserver;
  int ignoreservermem;
#ifdef MON_DRONES

  int droneentry;
  int dronenode;
#endif
#ifdef TRACK_CTCPVERSION

  int cversion;
  int cversionmem;
#endif
#endif
  int sendq;
#ifdef LISTSERV
  int topic;
  int topicmem;
  int topicinfo;
  int topicinfomem;
#endif
}
memcounts;

struct settings
{
  char name[MAXHOST];
  char sid[ sizeof(char*) * 4 ];
  int port;
  unsigned int r_time;
  char uplink[MAXHOST];
  char vhost[MAXHOST];
  char pass[MAXPASS];
  char desc[LINE];
  unsigned int pflags;
  unsigned int flags;
  char html[BUFSIZE];
  int html_time;
  char dump_file[BUFSIZE];
  int dump_time;
  char join_chans[BUFSIZE];
  char url[BUFSIZE];
  int flood;
  int flood_time;
  unsigned int default_flags;
  char netname[MAXNICK + 1];
  char admin_name[LINE];
  char admin_email[LINE];
#ifdef PUBSTATS

  char pub_chan[LINE];
#endif
#ifdef JUPESERV

  int jupevotes;
#endif

  int dcc_low_port;
  int dcc_high_port;
  int topchannum;
  int defaultlimit;
}
settings;

struct me
{
  time_t t_start;
  struct Server *s;
  struct Server *uplink;
  dlink_list chan_list;
  unsigned int cmdflags;
  struct hostent *local_host;
  char local_ip_str[MAXHOST];
  char *capabs;
#if defined(IRCD_HYB7) || defined(IRCD_RATBOX) || defined(IRCD_BAHAMUT) || defined(IRCD_HYBSVS)

  time_t eob_time;
#endif

  int max_fd;
}
me;

#ifdef STATSERV
struct StatServ
{
  char nick[MAXNICK + 1];
  char user[MAXUSER + 1];
  char host[MAXHOST];
  char desc[LINE];
  unsigned int flags;
  struct User *u;
}
StatServ;
#endif

struct Server
{
  char name[MAXHOST];
  char desc[LINE];
#ifdef TRACK_VERSION

  char version[BUFSIZE];
#endif
#ifdef TRACK_ADMIN

  char admin1[LINE];
  char admin2[LINE];
  char admin3[LINE];
#endif

  int hops;

  long hash;
  struct Stats *stats;
  long users;
  long invis;
  int opers;
  int away;

  time_t connected_since;

  time_t last_announce;
  unsigned int flags;
  struct Server *uplink;
};

struct User
{
  char nick[MAXNICK + 1];
  char hostname[MAXHOST];
  char username[MAXUSER + 1];
#ifdef TRACK_GECOS

  char *gecos;
#endif
#ifdef TRACK_CTCPVERSION

  char *version;
#endif

  struct Server *server;
  struct TLD *tld;
  struct MyUser *myuser;
  int flood;
  time_t t_flood;
  long hash;
#ifdef OPER_MODES

  unsigned int operflags;
#endif

  unsigned int flags;
  dlink_list channels;
};

#ifdef MONSERV
struct HashEnt
{
  struct HashEnt *next, *prev;
  char hashval[MAXUSERHOST];
  long hash;
  int count;
  dlink_list userlist;
};
#endif

struct Channel
{
  struct Channel *next, *prev;
  char name[CHANLEN];
  unsigned int modes;
  char key[KEYLEN];
  int limit;
  long ts;
  long hash;
  int nummembers;
  dlink_list members;
#ifdef LISTSERV
  char *topic;
  char *topicauthor;
  time_t topicts;
  time_t last;
#endif
};

struct ChanUser
{
  struct Channel *chan;
  struct User *user;
  unsigned int modes;
};

struct Hidden
{
  char name[MAXHOST];
  int perm;
};

struct Connection
{
  char name[LINE];
  int fd;
  int flags;
  char hbuffer[BUFSIZE + 1];
  struct MyUser *myuser;
  struct sockaddr_in *sa;
  time_t last;
  dlink_list sendq;
};

struct sendq {
  char *buf;
  int len;
  int pos;
};

struct Stats
{
  char name[MAXHOST];
  int numsplits;
  long maxusers;
  time_t t_maxusers;
  int maxopers;
  time_t t_maxopers;
  int maxaway;
  time_t t_maxaway;
  time_t lastseen;
  time_t starttime;
  unsigned int operkills;
  unsigned int serverkills;
};

struct daily
{
  int servers;
  time_t t_servers;
  long users;
  time_t t_users;
  int opers;
  time_t t_opers;
  long channels;
  time_t t_channels;
  long connections;
}
daily;

struct TLD
{
  struct TLD *next;
  long hash;
  char tld[MAXTLD];
  char country[LINE];
  char *native;
  int users;
};

struct MyUser
{
  char username[MAXNICK + 1];
  char password[LINE];
  struct User *u;
  struct Connection *conn;
#ifdef HAVE_LIBCRYPTO

  char *response;
  RSA *keyfile;
#endif

  unsigned int flags;
};

struct MsgTable
{
  char* name;
  long counter;
  int hash;
  struct MsgTable *next;
  int (*handler)();
};

#ifdef SPLITSERV

struct SpServer
{
  char name[MAXHOST];
  struct SpServer* uplink;
  int numleaf;
  time_t ts;
  dlink_list leaflist;
};

struct SplitServ
{
  char host[MAXHOST];
  char user[MAXUSER + 1];
  char nick[MAXNICK + 1];
  struct User *u;
}
SplitServ;

struct sp
{
  char uplink[MAXHOST];
  char desc[LINE];
  char version[LINE];
  int numserver;
  char join_chan[LINE];
  int delay;
  int text_time;
  long expire_time;
  long remind_time;
  unsigned int flags;
  char text_name[BUFSIZE];
  int map_setting;
  int split_setting;
  int dump_setting;
}
sp;

struct mapreturn
  {
    int count;
    int depth;
  };

#endif

struct AdminServ
{
  char host[MAXHOST];
  char user[MAXUSER + 1];
  char nick[MAXNICK + 1];
  char desc[LINE];
  struct User *u;
}
AdminServ;

#ifdef MONSERV
struct MonServ
{
  char host[MAXHOST];
  char user[MAXUSER + 1];
  char nick[MAXNICK + 1];
  char desc[LINE];
  struct User *u;
  dlink_list ignore_server_list;
#ifdef MON_DRONES

  dlink_list gecos_drone_list;
  dlink_list version_drone_list;
  dlink_list nick_drone_list;
  dlink_list channel_drone_list;
  dlink_list username_drone_list;
  dlink_list drone_users;
#endif
}
MonServ;

#ifdef MON_DRONES
struct DroneEntry
{
  char name[MAXUSERHOST];
  int hits;
};

struct DroneNode
{
  struct User *u;
  char reason[LINE];
};
#endif
#endif

#ifdef LISTSERV
struct ListServ
{
  char host[MAXHOST];
  char user[MAXUSER + 1];
  char nick[MAXNICK + 1];
  char desc[LINE];
  int default_max;
  struct User *u;
}
ListServ;
#endif

#ifdef JUPESERV

struct JupeServ
{
  char host[MAXHOST];
  char user[MAXUSER + 1];
  char nick[MAXNICK + 1];
  char desc[LINE];
  struct User *u;
}
JupeServ;

struct Jupe
{
  char jupe[MAXHOST];
  char oper[MAXNICK + 1];
  long ts;
  char reason[LINE];
};

struct JupeVote
{
  char server[MAXHOST];
  char oper[MAXNICK + 1];
  char oper_serv[MAXHOST];
  time_t ts;
  char reason[LINE];
};

#endif

struct HelpTable
{
  char* name;
  char* filename;
  int myuonly;
};

#endif
